package com.wondersgroup.framework.widget.taglib.grid;

import javax.servlet.jsp.JspException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.wondersgroup.framework.widget.annotations.WidgetTagAttribute;
import com.wondersgroup.framework.widget.context.DefaultSettings;
import com.wondersgroup.framework.widget.taglib.WidgetTagSupport;
import com.wondersgroup.framework.widget.validation.annotation.TagValidate;
import com.wondersgroup.framework.widget.validation.annotation.TypeValidate;
import com.wondersgroup.framework.widget.validation.annotation.ValueValidate;

@TagValidate
public abstract class AbstractGridTag extends WidgetTagSupport
{
  protected Log logger = LogFactory.getLog(getClass());
  private int width;
  private int height;
  private int minColumnWidth = 20;
  private String title;
  private String template;
  private String url;
  private String urlParams;

  @ValueValidate({"radio", "checkbox", "cell"})
  private String selectMode = "row";

  @TypeValidate
  private boolean enablePage = true;
  private int pageSize = DefaultSettings.getInt("widget.pageSize");
  private int maxPageSize = -1;

  @TypeValidate
  private boolean exportable;
  private String container;

  @TypeValidate
  private boolean stripeRows;
  private String stripleColor;

  @TypeValidate
  private boolean forceFit = DefaultSettings.getBoolean("widget.grid.forceFit");

  @TypeValidate
  private boolean autoLoad = false;

  @TypeValidate
  private boolean loadMask = true;

  @TypeValidate
  private boolean enableColumnMove = true;

  @TypeValidate
  private boolean enableColumnResize = true;

  @TypeValidate
  private boolean enableHdMenu = true;

  @TypeValidate
  private boolean enableColumnHide = true;

  @TypeValidate
  private boolean remoteSort = false;

  @TypeValidate
  private boolean showGlobalStat;

  @TypeValidate
  private boolean remoteGlobalStat;
  private String summaryText = "合计";

  @TypeValidate
  private boolean exportInServer = DefaultSettings.getBoolean("widget.grid.exportInServer");

  @TypeValidate
  private boolean exportColumnSelect = DefaultSettings.getBoolean("widget.grid.exportColumnSelect");

  @TypeValidate
  private boolean rowSelectSummary;
  private String contextMenu;

  @ValueValidate({"", "top", "bottom"})
  private String toolbarPos = "";

  public int getWidth()
  {
    return this.width;
  }

  public int getHeight()
  {
    return this.height;
  }

  public int getMinColumnWidth()
  {
    return this.minColumnWidth;
  }

  public String getTitle()
  {
    return this.title;
  }

  public String getTemplate()
  {
    return this.template;
  }

  public String getUrl()
  {
    return this.url;
  }

  public String getUrlParams()
  {
    return this.urlParams;
  }

  public String getSelectMode()
  {
    return this.selectMode;
  }

  public boolean isEnablePage()
  {
    return this.enablePage;
  }

  public int getPageSize()
  {
    return this.pageSize;
  }

  public boolean isExportable()
  {
    return this.exportable;
  }

  public String getContainer()
  {
    return this.container;
  }

  public boolean isStripeRows()
  {
    return this.stripeRows;
  }

  public boolean isForceFit()
  {
    return this.forceFit;
  }

  public String getStripleColor()
  {
    return this.stripleColor;
  }

  public boolean isAutoLoad()
  {
    return this.autoLoad;
  }

  public boolean isLoadMask()
  {
    return this.loadMask;
  }

  public boolean isEnableColumnMove()
  {
    return this.enableColumnMove;
  }

  public boolean isEnableColumnResize()
  {
    return this.enableColumnResize;
  }

  public boolean isEnableHdMenu()
  {
    return this.enableHdMenu;
  }

  @WidgetTagAttribute(description="[可选]表格宽度，设置为0时，将采用autoWidth策略；默认值：0", required=false, type="int")
  public void setWidth(int paramInt)
  {
    this.width = paramInt;
  }

  @WidgetTagAttribute(description="[可选]表格高度，设置为0时，将采用autoHeight策略；默认值：0", required=false, type="int")
  public void setHeight(int paramInt)
  {
    this.height = paramInt;
  }

  @WidgetTagAttribute(description="[可选]列宽度最小值，默认为20px。", required=false, type="int")
  public void setMinColumnWidth(int paramInt)
  {
    this.minColumnWidth = paramInt;
  }

  @WidgetTagAttribute(description="[可选]表格标题，没有默认值，不设置不显示标题。", required=false, type="String")
  public void setTitle(String paramString)
  {
    this.title = paramString;
  }

  @WidgetTagAttribute(description="[可选]表格显示模版配置，目前不支持该属性配置。", required=false, type="String")
  public void setTemplate(String paramString)
  {
    this.template = paramString;
  }

  @WidgetTagAttribute(description="[必须]表格远程数据URL。", required=true, type="String")
  public void setUrl(String paramString)
  {
    this.url = paramString;
  }

  @WidgetTagAttribute(description="[可选]表格远程数据过滤条件，设置为JSON数据格式，示例:{sex:1,age:20}。", required=false, type="String")
  public void setUrlParams(String paramString)
  {
    this.urlParams = paramString;
  }

  @WidgetTagAttribute(description="[可选]选择模式设置，可选值['radio','checkbox']，设置默认在第一列渲染出radio或者checkbox，不设置只能进行单行选择。", required=false, type="String")
  public void setSelectMode(String paramString)
  {
    this.selectMode = paramString;
  }

  @WidgetTagAttribute(description="[可选]分页标志，默认值为true。", required=false, type="boolean")
  public void setEnablePage(boolean paramBoolean)
  {
    this.enablePage = paramBoolean;
  }

  @WidgetTagAttribute(description="[可选]分页大小，，默认值为10。", required=false, type="int")
  public void setPageSize(int paramInt)
  {
    this.pageSize = paramInt;
  }

  @WidgetTagAttribute(description="[可选]导出标志，默认值为false。", required=false, type="boolean")
  public void setExportable(boolean paramBoolean)
  {
    this.exportable = paramBoolean;
  }

  @WidgetTagAttribute(description="[可选]渲染容器设置，设置为某DIV的id值。", required=false, type="String")
  public void setContainer(String paramString)
  {
    this.container = paramString;
  }

  @WidgetTagAttribute(description="[可选]表格斑马线标志，设置了隔行颜色区分。", required=false, type="boolean")
  public void setStripeRows(boolean paramBoolean)
  {
    this.stripeRows = paramBoolean;
  }

  @WidgetTagAttribute(description="[可选]表格斑马线颜色实现，可直接配置颜色名称(如：red)或者配置颜色值(如:#c0c0c0)。", required=false, type="String")
  public void setStripleColor(String paramString)
  {
    this.stripleColor = paramString;
  }

  @WidgetTagAttribute(description="[可选]强制让表格在固定的宽度（用表格的width，如果为null就用表格父容器的宽度）里中调整各列到合适的宽度, 默认值为true", required=false, type="boolean")
  public void setForceFit(boolean paramBoolean)
  {
    this.forceFit = paramBoolean;
  }

  @WidgetTagAttribute(description="[可选]表格数据(store)首次是否加载，默认值为:true。", required=false, type="boolean")
  public void setAutoLoad(boolean paramBoolean)
  {
    this.autoLoad = paramBoolean;
  }

  @WidgetTagAttribute(description="[可选]数据加载遮罩，默认值为true", required=false, type="boolean")
  public void setLoadMask(boolean paramBoolean)
  {
    this.loadMask = paramBoolean;
  }

  @WidgetTagAttribute(description="[可选]列可移动开关，默认值为true。", required=false, type="boolean")
  public void setEnableColumnMove(boolean paramBoolean)
  {
    this.enableColumnMove = paramBoolean;
  }

  @WidgetTagAttribute(description="[可选]列宽度大小可调开关，默认值为true。", required=false, type="boolean")
  public void setEnableColumnResize(boolean paramBoolean)
  {
    this.enableColumnResize = paramBoolean;
  }

  @WidgetTagAttribute(description="[可选]菜单开关，默认值为true。", required=false, type="boolean")
  public void setEnableHdMenu(boolean paramBoolean)
  {
    this.enableHdMenu = paramBoolean;
  }

  public boolean isRemoteSort()
  {
    return this.remoteSort;
  }

  @WidgetTagAttribute(description="[可选]是否后台全局排序，默认值为false。", required=false, type="boolean")
  public void setRemoteSort(boolean paramBoolean)
  {
    this.remoteSort = paramBoolean;
  }

  public boolean isShowGlobalStat()
  {
    return this.showGlobalStat;
  }

  @WidgetTagAttribute(description="[可选]是否全局统计，默认为false")
  public void setShowGlobalStat(boolean paramBoolean)
  {
    this.showGlobalStat = paramBoolean;
  }

  public boolean isRemoteGlobalStat()
  {
    return this.remoteGlobalStat;
  }

  @WidgetTagAttribute(description="[可选]是否从后台获取全局统计数据，默认为false")
  public void setRemoteGlobalStat(boolean paramBoolean)
  {
    this.remoteGlobalStat = paramBoolean;
  }

  public boolean isExportInServer()
  {
    return this.exportInServer;
  }

  @WidgetTagAttribute(description="[可选]是否从后台获取全部数据导出，默认为false(此选项用于分页表格的全部导出，默认从前台获取所有数据)")
  public void setExportInServer(boolean paramBoolean)
  {
    this.exportInServer = paramBoolean;
  }

  public boolean isExportColumnSelect()
  {
    return this.exportColumnSelect;
  }

  @WidgetTagAttribute(description="[可选]是否在导出之前进行列选择，默认为true)")
  public void setExportColumnSelect(boolean paramBoolean)
  {
    this.exportColumnSelect = paramBoolean;
  }

  public String getSummaryText()
  {
    return this.summaryText;
  }

  @WidgetTagAttribute(description="[可选]表格统计栏标题，默认为'合计'")
  public void setSummaryText(String paramString)
  {
    this.summaryText = paramString;
  }

  public boolean isRowSelectSummary()
  {
    return this.rowSelectSummary;
  }

  @WidgetTagAttribute(description="[可选]是否允许选中行统计，默认为false")
  public void setRowSelectSummary(boolean paramBoolean)
  {
    this.rowSelectSummary = paramBoolean;
  }

  public String getToolbarPos()
  {
    return this.toolbarPos;
  }

  @WidgetTagAttribute(description="[可选]工具栏位置设置，可选值['','top','bottom']，设置所有按钮位置都在顶部或底部；不设置自定义工具栏在顶部，分页和导出栏在底部")
  public void setToolbarPos(String paramString)
  {
    this.toolbarPos = paramString;
  }

  public String getContextMenu()
  {
    return this.contextMenu;
  }

  @WidgetTagAttribute(description="[可选]上下文菜单的ID")
  public void setContextMenu(String paramString)
  {
    this.contextMenu = paramString;
  }

  public Log getLogger()
  {
    return this.logger;
  }

  public void setLogger(Log paramLog)
  {
    this.logger = paramLog;
  }

  public int getMaxPageSize()
  {
    return this.maxPageSize;
  }

  @WidgetTagAttribute(description="[可选]限制分页栏每页显示记录条数")
  public void setMaxPageSize(int paramInt)
  {
    this.maxPageSize = paramInt;
  }

  public boolean isEnableColumnHide()
  {
    return this.enableColumnHide;
  }

  @WidgetTagAttribute(description="[可选]是否启用表格头菜单中的隐藏列功能，默认为true")
  public void setEnableColumnHide(boolean paramBoolean)
  {
    this.enableColumnHide = paramBoolean;
  }

  public int doEndTag()
    throws JspException
  {
    int i = super.doEndTag();
    setUrlParams("");
    return i;
  }

  public String getStyle()
  {
    String str = super.getStyle();
    if ((str == null) || (str.trim().length() == 0))
    {
      str = "text-align:left";
      setStyle("text-align:left");
    }
    return str;
  }
}